from scipy.stats import linregress
import numpy as np


def fit_trend_line(prices):
    """拟合趋势线（最小二乘法）
    :param prices: 包含日期索引和价格值的Series
    :return: 包含斜率(slope)和截距(intercept)的字典
    """
    if len(prices) < 2:
        return None

    x = np.array([p.toordinal() for p in prices.index])
    y = prices.values
    slope, intercept, _, _, _ = linregress(x, y)

    return {
        'slope': slope,
        'intercept': intercept,
        'start_date': prices.index[0],
        'end_date': prices.index[-1]
    }